﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;

namespace Intorise.Game.MU.Entity
{
    public class LoginEntity
    {
        public LoginEntity()
        {
            ID = Guid.NewGuid();
            LoginStatus = LoginStatusEnum.Waiting;
        }

        [Key]
        public Guid ID { get; set; }
        public string Account { get; set; }
        public string Password { get; set; }
        public string ServerNo { get; set; }
        public string Sign { get; set; }
        public string ServerIP { get; set; }
        public int Port { get; set; }
        public string TicketTime { get; set; }
        [NotMapped]
        public LoginStatusEnum LoginStatus { get; set; }
        [NotMapped]
        public LoginResultEnum LoginResult { get; set; }
        public DateTime? CompletedTime { get; set; }
        [NotMapped]
        public DateTime? RegisterTime { get; set; }
        [NotMapped]
        public DateTime? StartTime { get; set; }
        [NotMapped]
        public List<Cookie> Cookies { get; set; }
        /// <summary>
        /// 登录cookie信息
        /// </summary>
        [JsonIgnore]
        public string CookiesString { get; set; }

        public void ProcessCookieString()
        {
            CookiesString = JsonConvert.SerializeObject(Cookies);
        }

        public void ProcessCookieList()
        {
            Cookies = JsonConvert.DeserializeObject<List<Cookie>>(CookiesString);
        }
    }

    public enum LoginStatusEnum
    {
        Waiting,
        Logining,
        Completed
    }

    public enum LoginResultEnum
    {
        Success,
        Failure,
        WrongPassword,
        TryTooManyTimes,
        NeedCode,
        UnkowError,
        Banned
    }
}